program main
    implicit none
    real :: A(3,2)
    real,allocatable :: B(:)
    data A /1,2,3,4,5,6/
    interface
        subroutine mmax(a,b,m,n,k)
            real :: a(m,n)
            real,allocatable :: b(:)
            integer :: m,n,k
        end subroutine
    end interface
    call mmax(A,B,3,2,1)
    write(*,*)'k=1:',B
    deallocate(B)
    call mmax(A,B,3,2,2)
    write(*,*)'k=2:',B
end program main
subroutine mmax(A,B,m,n,k)
    real :: A(m,n)
    real,allocatable :: B(:)
    integer :: m,n,k,i
    if(k==1)then
        allocate(B(n))
        do i=1,n
            B(i)=maxval(A(:,i))
        end do
    else
        allocate(B(m))
        do i=1,m
            B(i)=maxval(A(i,:))
        end do
    end if
end subroutine
